#ifndef ROUTE_H
#define ROUTE_H

#include "ServerStruct.h"
#include "common/YXResult.h"

#define REQUEST_BODY_ANNOTATION "@RequestBody"
#define PATH_VARIABLE_ANNOTATION "@PathVariable"


typedef YXResult *(*RouteHandler)(Request *request, Response *response);
typedef YXResult *(*BeforeRouteHandler)(Request *request, Response *response, void *privateData);

typedef struct PathVariblePrivateData {
    int start;
    int count;
} PathVariblePrivateData;

typedef struct BeforeRouteHandlerWarpper {
    BeforeRouteHandler                handler;
    struct BeforeRouteHandlerWarpper *next;
    void                             *privateData;
} BeforeRouteHandlerWarpper;

typedef struct {
    BeforeRouteHandlerWarpper *beforeRouteHandlerLinkedList;
    RouteHandler               mainHandler;
} EnhancedRouteHandler;


void         addRoute(char *method, char *path, char *annotation, RouteHandler handler);
EnhancedRouteHandler* getGetRouteHandler(char *path);
EnhancedRouteHandler* getPostRouteHandler(char *path);
EnhancedRouteHandler* getPutRouteHandler(char *path);
EnhancedRouteHandler* getDeleteRouteHandler(char *path);

#endif // ROUTE_H
